<?php


namespace app\yhk\controller;


use app\yhk\model\Member;

class test
{
    public function server()
    {
        $year = input('get.year');
        if (($year % 4 == 0) && ($year % 100 != 0) || ($year % 400 == 0)) {
            echo $year . '年是闰年';
        } else {
            echo $year . '年不是闰年';
        }
    }

    public function second()
    {
        $number = input('get.number');
        $line = 1;
        while ($line <= $number) {
            $empty_pos = $star_pos = 1;
            $empty = $number - $line;
            $star = 2 * $line - 1;
            while ($empty_pos <= $empty) {
                echo '&nbsp;';
                ++$empty_pos;
            }
            while ($star_pos <= $star) {
                echo '*';
                ++$star_pos;
            }
            echo '<br>';
            ++$line;
        }

    }

    public function third()
    {
        $total = 0;
        $i = input('get.i');
        $j = input('get.j');
        while ($i <= $j) {
            $total += $i;
            $i++;
        }
        echo $total;

    }

    public function fourth($n)
    {
        $i = 2;
        $n;
        $sum = 1;
        $n = input('get.n');
        if ($n == 1 || $n == 0) {
            echo("阶乘结果为1！");
        }
        while ($i <= $n) {
            $sum = $sum * $i;
            $i++;
        }
        echo("阶乘的结果是:" . $sum);
    }

    public function fifth()
    {
        $path = 'D:\Altium Designer 1_22_33';
        echo getFileExt($path);
    }

    public function sixth()
    {
       $id = input('get.id');
       $idArray = explode('.',$id);
       foreach ($idArray as $value){
           echo $value.'<br>';
       }
    }

    public function seventh()
    {
       $goods=array(
           array('name'=>'主板','price'=>'379','producing'=>'广东','num'=>3),
        array('name'=>'显卡','price'=>'799','producing'=>'上海','num'=>2),
        array('name'=>'硬盘','price'=>'589','producing'=>'北京','num'=>5)
       );

       $total = 0;
       $str = "<table>";
       $str.="<tr><td>商品名称</td><td>价格</td><td>产地</td>";
       $str.="<td>数量（件）</td><td>总价（元）</td></tr>";
       foreach ($goods as $values){
           $str.='<tr>';
           foreach ($values as $v){
               $str.='<td>'.$v.'</td>';
           }
           $sum = $values['price']*$values['num'];
           $str.='<td>'.$sum.'</td>';
           $str.='</tr>';
           $total+=$sum;
       }
       $str.="<tr><td>小计：".$total."元</td></tr></table>";
       echo $str;
    }

    public function suzu()
    {
        $array[0] = '这是第一个铁元素';
        $array[1] = '这是第一个修改后的铁元素';
        $array[2] = '这是第二个铁元素';
        $array[] = '这是第N个铁元素';
        //echo json_encode($array);
       // echo '<br>';

        /*echo '第一种遍历方式FOT循环'.'<br>';
        for($i = 0;$i<=sizeof($array);$i++){
            echo $array[$i].'<br>';
        }*/

        /*echo '第二种遍历方式FOT循环'.'<br>';
        foreach ($array as $value){
            echo $value.'<br>';
        }*/

        echo '第三种遍历方式FOT循环'.'<br>';
        foreach ($array as $key =>$value){
            echo '键：'.$key.'|值：' .$value .'<br>';
        }
    }

    public function array1()
    {
        $array =array();
        $array2=array();
        $array2['one']='1';
        $array2['two']='2';
        $array2['thr']='3';
        $array2['fou']='4';
        $array['onearray']=$array2;
        $array3=array();
        $array3['fiv']='5';
        $array3['six']='6';
        $array3['sev']='7';
        $array3['eie']='8';
        $array['twoarray']=$array3;
        foreach ($array as $value){
            foreach ($value as $val){
            echo $val.'<br>';
            }
        }
        foreach ($array as $key =>$value){
            foreach ($value as $k=>$v){
                echo $v.'<br>';
            }
        }
    }

    public function eigth()
    {
        $moble = input('get.mobile');
        if (empty($moble)) {
            echo '手机号码为空';
            die();
        }
       $memberModel = new Member();
       $data = $memberModel->where('member_mobile','=',$mobile)->select();
       echo json_encode($data);
    }


}
